package com.bestsoft.web.controller.picCategory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.flow.domain.PicCategory;
import com.bestsoft.flow.service.IPicCategoryService;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.common.core.page.TableDataInfo;

/**
 * 图片分类管理Controller
 * 
 * @author ruoyi
 * @date 2023-08-16
 */
@RestController
@RequestMapping("/pic/category")
public class PicCategoryController extends BaseController
{
    @Autowired
    private IPicCategoryService picCategoryService;

    /**
     * 查询图片分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('pic:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(PicCategory picCategory)
    {
        startPage();
        List<PicCategory> list = picCategoryService.selectPicCategoryList(picCategory);
        return getDataTable(list);
    }

    /**
     * 导出图片分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('pic:category:export')")
    @Log(title = "图片分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PicCategory picCategory)
    {
        List<PicCategory> list = picCategoryService.selectPicCategoryList(picCategory);
        ExcelUtil<PicCategory> util = new ExcelUtil<PicCategory>(PicCategory.class);
        util.exportExcel(response, list, "图片分类管理数据");
    }

    /**
     * 获取图片分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pic:category:query')")
    @GetMapping(value = "/{picId}")
    public AjaxResult getInfo(@PathVariable("picId") Long picId)
    {
        return success(picCategoryService.selectPicCategoryByPicId(picId));
    }

    /**
     * 新增图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('pic:category:add')")
    @Log(title = "图片分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PicCategory picCategory)
    {
        return toAjax(picCategoryService.insertPicCategory(picCategory));
    }

    /**
     * 修改图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('pic:category:edit')")
    @Log(title = "图片分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PicCategory picCategory)
    {
        return toAjax(picCategoryService.updatePicCategory(picCategory));
    }

    /**
     * 删除图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('pic:category:remove')")
    @Log(title = "图片分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{picIds}")
    public AjaxResult remove(@PathVariable Long[] picIds)
    {
        return toAjax(picCategoryService.deletePicCategoryByPicIds(picIds));
    }
}
